
//LCR_08.剧情触发时间
class Solution {
public:
    vector<int> getTriggerTime(vector<vector<int>>& increase, vector<vector<int>>& requirements) {
        //使用三个数组存放每个属性在每个时间的值
        int n=increase.size(),m=requirements.size();
        vector<int> civi(n+1);
        vector<int> reso(n+1);
        vector<int> peop(n+1);

        for(int i=1;i<=n;i++)
        {
            civi[i]=civi[i-1]+increase[i-1][0];
            reso[i]=reso[i-1]+increase[i-1][1];
            peop[i]=peop[i-1]+increase[i-1][2];
        }

        //遍历requirements进行查找
        vector<int> ret;
        for(int i=0;i<m;i++)
        {
            int a1=lower_bound(civi.begin(),civi.end(),requirements[i][0])-civi.begin();
            int a2=lower_bound(reso.begin(),reso.end(),requirements[i][1])-reso.begin();
            int a3=lower_bound(peop.begin(),peop.end(),requirements[i][2])-peop.begin();

            if(a1==civi.size()||a2==reso.size()||a3==peop.size()) ret.push_back(-1);
            else ret.push_back(max({a1,a2,a3}));
        }
        return ret;
    }
};